<template>
	<view class="jnpf-wrap jnpf-wrap-workflow">
		<u-form :model="dataForm" ref="dataForm" :errorType="['toast']" label-position="left" label-width="150"
			label-align="left">
			<u-form-item label="采购单别" v-if="judgeShow('tc001')">
				<u-input v-model="dataForm.tc001" placeholder="采购单别" :disabled="judgeWrite('tc001')"></u-input>
			</u-form-item>
			<u-form-item label="采购单号" v-if="judgeShow('tc002')">
				<u-input v-model="dataForm.tc002" placeholder="采购单号" :disabled="judgeWrite('tc002')"></u-input>
			</u-form-item>
			<!-- 		<u-form-item label="请购部门" v-if="judgeShow('ti006')">
				<u-tag :text="ti006Name" type="success" />
			</u-form-item> -->
			<u-form-item label="单据日期" v-if="judgeShow('tc024')">
				<u-input v-model="dataForm.tc024" placeholder="单据日期" :disabled="judgeWrite('tc024')"></u-input>
			</u-form-item>
			<u-form-item label="供应商" v-if="judgeShow('tc004')">
				<u-input v-model="dataForm.tc004" placeholder="供应商" :disabled="judgeWrite('tc004')"></u-input>
			</u-form-item>
			<u-form-item label="供应商简称" v-if="judgeShow('tc004')">
				<u-input v-model="tc004Name" placeholder="供应商简称" disabled></u-input>
			</u-form-item>
			<u-form-item label="采购人员" v-if="judgeShow('tc011')">
				<view v-for="(item, index) in tc011Name" :key="index" style="margin-left: 5px">
					<u-tag :text="item" type="success" />
				</view>
			</u-form-item>
			<!-- 			<u-form-item label="来源单号" v-if="judgeShow('ta005')">
				<u-input v-model="dataForm.ta005" placeholder="来源单号" :disabled="judgeWrite('ta005')"></u-input>
			</u-form-item>
			<u-form-item label="请购人员" v-if="judgeShow('ti007')">
				<u-tag :text="ti007Name" type="success" />
			</u-form-item> -->
			<u-form-item label="交易币种" v-if="judgeShow('tc005')">
				<u-input v-model="dataForm.tc005" placeholder="交易币种" :disabled="judgeWrite('tc005')"></u-input>
			</u-form-item>
			<u-form-item label="汇率" v-if="judgeShow('tc006')">
				<u-input v-model="dataForm.tc006" placeholder="汇率" :disabled="judgeWrite('tc006')"></u-input>
			</u-form-item>
			<u-form-item label="付款条件" v-if="judgeShow('tc008')">
				<u-input v-model="dataForm.tc008" placeholder="付款条件" :disabled="judgeWrite('tc008')"></u-input>
			</u-form-item>
			<u-form-item label="税率" v-if="judgeShow('tc026')">
				<u-input v-model="dataForm.tc026" placeholder="税率" :disabled="judgeWrite('tc026')"></u-input>
			</u-form-item>
			<u-form-item label="采购金额" v-if="judgeShow('tc019')">
				<u-input v-model="dataForm.tc019" placeholder="采购金额" :disabled="judgeWrite('tc019')"></u-input>
			</u-form-item>
			<u-form-item label="税额" v-if="judgeShow('tc020')">
				<u-input v-model="dataForm.tc020" placeholder="税额" :disabled="judgeWrite('tc020')"></u-input>
			</u-form-item>
			<u-form-item label="含税金额(RMB)" v-if="judgeShow('udf60')">
				<u-input v-model="dataForm.udf60" placeholder="含税金额(RMB)" :disabled="judgeWrite('udf60')"></u-input>
			</u-form-item>
			<u-form-item label="送货地址" v-if="judgeShow('tc021')">
				<u-input v-model="dataForm.tc021" placeholder="送货地址" :disabled="judgeWrite('tc021')"></u-input>
			</u-form-item>
			<u-divider color="#fa3534" type='warning' v-if="dataForm.purtdList!=0">详细信息</u-divider>
			<view class="jnpf-table" style="margin-top: 24rpx;">
				<view class="jnpf-table-item" style="margin-bottom: 24rpx;" v-for="(item,i) in dataForm.purtdList"
					:key="i">
					<u-form-item label="序号">
						{{i+1}}
					</u-form-item>
					<u-form-item label="品号" v-if="judgeShow('purtdList-td005')">
						<u-input v-model="item.td005" placeholder="品号"
							:disabled="judgeWrite('purtdList-td005') "></u-input>
					</u-form-item>
					<u-form-item label="规格" v-if="judgeShow('purtdList-td006')">
						<u-input v-model="item.td006" placeholder="规格"
							:disabled="judgeWrite('purtdList-td006') "></u-input>
					</u-form-item>
					<u-form-item label="采购数量" v-if="judgeShow('purtdList-td008')">
						<u-input v-model="item.td008" placeholder="采购数量"
							:disabled="judgeWrite('purtdList-td008') "></u-input>
					</u-form-item>
					<u-form-item label="采购单价" v-if="judgeShow('purtdList-td010')">
						<u-input v-model="item.td010" placeholder="采购单价"
							:disabled="judgeWrite('purtdList-td010') "></u-input>
					</u-form-item>
					<u-form-item label="采购金额" v-if="judgeShow('purtdList-td011')">
						<u-input v-model="item.td011" placeholder="采购金额"
							:disabled="judgeWrite('purtdList-td011') "></u-input>
					</u-form-item>
					<u-form-item label="已交数量" v-if="judgeShow('purtdList-td015')">
						<u-input v-model="item.td015" placeholder="已交数量"
							:disabled="judgeWrite('purtdList-td015') "></u-input>
					</u-form-item>
					<u-form-item label="单位" v-if="judgeShow('purtdList-td009')">
						<u-input v-model="item.td009" placeholder="单位"
							:disabled="judgeWrite('purtdList-td009') "></u-input>
					</u-form-item>
					<u-form-item label="预交货日" v-if="judgeShow('purtdList-td012')">
						<u-input v-model="item.td012" placeholder="预交货日"
							:disabled="judgeWrite('purtdList-td012') "></u-input>
					</u-form-item>
					<u-form-item label="备注" v-if="judgeShow('purtdList-td014')">
						<u-input v-model="item.td014" placeholder="备注"
							:disabled="judgeWrite('purtdList-td014') "></u-input>
					</u-form-item>

				</view>
			</view>
		</u-form>
	</view>
</template>

<script>
	import {
		getPurtc
	} from '@/api/workFlow/flowEngine'
	import {
		getDataInterfaceDataInfo,
		getDictionaryDataSelector,
		getDataInterfaceRes,
		getUserAll,
		Interface,
	} from '@/api/common'

	import comMixin from '../mixin'
	import {
		Info,
		Create,
		Update
	} from '@/api/apply/order'
	export default {
		name: 'crmOrder',
		mixins: [comMixin],
		data() {
			return {
				dataForm: {},
				id: '',
				dataForm: {},

				tc011Name: [],
				sourceList: [],
				ti006Name: '',
				ti007Name: '',
				tc004Name: '',
			}
		},

		methods: {
			gettc008Options() {
				getDataInterfaceRes("362115953258928709").then((res) => {
					console.log(' res.data.data;', res.data.data);
				});
			},
			init(data, id, flowFormContentJson) {
				this.setting = data
				this.id = id
				this.getInfo(data)
				this.gettc008Options()
			},
			getInfo(data) {
				getPurtc(data.id).then(res => {
					console.log('res', res);
					if (res.code == 200) {
						this.dataForm = res.data
						this.getUser()
						this.getDepartment(this.dataForm.ta004)
						this.getPersonnel(this.dataForm.ti007)
						this.getSource()
					}
				})
			},
			getUser() {
				getUserAll().then((res) => {

					this.tc011Name = res.data.filter((item) => this.dataForm.tc011.includes(item.account)).map((
							item) =>
						item.realName);
					console.log('this.tc011Name', this.tc011Name);
				});
			},
			// 获取部门
			getDepartment(id) {
				let interfaceId = '362111557984852549'
				let data = {
					id,
					interfaceId,
					propsValue: 'ME001',
					relationField: 'JoinStr',
				}
				getDataInterfaceDataInfo(interfaceId, data).then(res => {
					this.ti006Name = res.data.JoinStr;
				})
			},
			// 获取供应商
			getDepartment(id) {
				let interfaceId = '381247065990113925'
				let data = {
					id,
					interfaceId,
					propsValue: 'MA001',
					relationField: 'MA001',
				}
				getDataInterfaceDataInfo(interfaceId, data).then(res => {
					this.tc004Name = res.data.MA003;
				})
			},
			// 获取人员

			getPersonnel(id) {
				let interfaceId = '438122284524265733'
				let data = {
					id,
					interfaceId,
					propsValue: 'MV001',
					relationField: 'JoinStr',
				}
				getDataInterfaceDataInfo(interfaceId, data).then(res => {
					this.ti007Name = res.data.JoinStr;
				})
			},
			// 获取仓库
			getWarehouse(item) {
				let interfaceId = '362114335423601221'
				let data = {
					id: item.tb008,
					interfaceId,
					propsValue: 'MC001',
					relationField: 'MC001',
				}
				getDataInterfaceDataInfo(interfaceId, data).then(res => {
					this.$set(item, 'tb008', MC002);
					return res.data.MC002
				})
			},
			getSource() {
				getDictionaryDataSelector("474002610777559109").then(res => {
					this.sourceList = res.data.list.filter((item) => this.dataForm.ta009.includes(item.enCode))
						.map((
								item) =>
							item.fullName);
				});
			},
			selfGetInfo() {
				Info(this.setting.id).then(res => {
					this.dataForm = res.data
					if (this.dataForm.fileJson) {
						this.fileList = JSON.parse(this.dataForm.fileJson)
					}
				})
			},
			selfSubmit() {
				this.dataForm.status = this.eventType === 'submit' ? 0 : 1
				if (this.eventType === 'save') return this.selfHandleRequest()
				uni.showModal({
					title: '提示',
					content: '您确定要提交当前流程吗？',
					success: res => {
						if (res.confirm) {
							this.selfHandleRequest()
						}
					}
				})
			},
			selfHandleRequest() {
				if (!this.dataForm.id) delete(this.dataForm.id)
				const formMethod = this.dataForm.id ? Update : Create
				formMethod(this.dataForm).then(res => {
					uni.showToast({
						title: res.msg,
						complete: () => {
							setTimeout(() => {
								uni.$emit('refresh')
								uni.navigateBack()
							}, 1500)
						}
					})
				})
			},

		}
	}
</script>